//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.andromeda.androbench2;

import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
import android.os.Build.VERSION;
import android.provider.Settings.Secure;
import android.util.Pair;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class GetInfo {
    static final int ERROR = -1;
    static final String ERROR_STR = "-1";
    static final int STATFS_BAVAIL = 2;
    static final int STATFS_BFREE = 1;
    static final int STATFS_BLOCKS = 0;
    static final int STATFS_BSIZE = 5;
    static final int STATFS_FFREE = 4;
    static final int STATFS_FILES = 3;
    static final int STATFS_FRSIZE = 6;
    static final int STATFS_SIZE = 7;
    static final String UNKNOWN = "unknown";

    static {
        System.loadLibrary("Interface_JNI");
    }

    public GetInfo() {
    }

    public static native int GET_STATFS_FROM_PATH(String var0, long[] var1);

    public static String getCpuHardware() {
        String var0 = "unknown";

        boolean var10001;
        BufferedReader var2;
        try {
            String[] var1 = new String[]{"/system/bin/sh", "-c", "cat /proc/cpuinfo"};
            var2 = new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec(var1).getInputStream()));
        } catch (Exception var11) {
            var10001 = false;
            return var0;
        }

        while(true) {
            String var4;
            try {
                var4 = var2.readLine();
            } catch (IOException var10) {
                var10001 = false;
                break;
            }

            if (var4 == null) {
                break;
            }

            String[] var5;
            try {
                var5 = var4.split(" |\t");
                if (!var5[0].equals("Hardware")) {
                    continue;
                }
            } catch (Exception var9) {
                var10001 = false;
                break;
            }

            var0 = "";
            int var6 = 2;

            while(true) {
                String var7;
                try {
                    if (var6 >= var5.length) {
                        return var0;
                    }

                    var7 = var0 + var5[var6] + " ";
                } catch (Exception var8) {
                    var10001 = false;
                    return var0;
                }

                var0 = var7;
                ++var6;
            }
        }

        return var0;
    }

    public static String getInternalDataPartitionDevName() {
        String var0 = "unknown";

        boolean var10001;
        label90: {
            BufferedReader var2;
            try {
                String[] var1 = new String[]{"/system/bin/sh", "-c", "cat /proc/mounts"};
                var2 = new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec(var1).getInputStream()));
            } catch (IOException var22) {
                var10001 = false;
                break label90;
            }

            while(true) {
                String var13;
                try {
                    var13 = var2.readLine();
                } catch (IOException var21) {
                    var10001 = false;
                    break;
                }

                if (var13 == null) {
                    break;
                }

                try {
                    String[] var14 = var13.split(" ");
                    if (var14[1].equals("/data")) {
                        var0 = var14[0];
                    }
                } catch (Exception var20) {
                    var10001 = false;
                    break;
                }
            }
        }

        if (var0.equals("unknown")) {
            return var0;
        } else {
            String var4 = "unknown";

            Exception var10000;
            label72: {
                label96: {
                    String var9;
                    try {
                        var9 = (new File(var0)).getCanonicalPath().toString();
                        System.out.println("getInternalDataPartitionDevName(): " + var9);
                        String[] var10 = var9.split("/");
                        if (var10.length > 0) {
                            var4 = var10[-1 + var10.length];
                        }
                    } catch (IOException var19) {
                        var10000 = var19;
                        var10001 = false;
                        break label96;
                    }

                    String var12;
                    try {
                        String[] var11 = new String[]{"/system/bin/sh", "-c", "ls -l " + var9};
                        var12 = (new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec(var11).getInputStream()))).readLine();
                    } catch (IOException var18) {
                        var10000 = var18;
                        var10001 = false;
                        break label96;
                    }

                    if (var12 == null) {
                        break label72;
                    }

                    try {
                        if (var12.charAt(0) != 'b') {
                            return "unknown";
                        }
                        break label72;
                    } catch (Exception var17) {
                        var10000 = var17;
                        var10001 = false;
                    }
                }

                Exception var5 = var10000;
                var5.printStackTrace();
            }

            label56: {
                String var8;
                label55: {
                    label97: {
                        try {
                            String[] var7 = new String[]{"/system/bin/sh", "-c", "ls /sys/block/" + var4 + "/slaves"};
                            var8 = (new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec(var7).getInputStream()))).readLine();
                        } catch (IOException var16) {
                            var10000 = var16;
                            var10001 = false;
                            break label97;
                        }

                        if (var8 == null) {
                            break label56;
                        }

                        try {
                            System.out.println("yes slave");
                            break label55;
                        } catch (Exception var15) {
                            var10000 = var15;
                            var10001 = false;
                        }
                    }

                    Exception var6 = var10000;
                    var6.printStackTrace();
                    break label56;
                }

                var4 = var8;
            }

            System.out.println("getInternalDataPartitionDevName(): " + var4);
            return var4;
        }
    }

    public static String getInternalDevName() {
        String var0 = getInternalDataPartitionDevName();
        int var1 = var0.lastIndexOf(112);
        String var3;
        if (var1 >= 0) {
            var3 = var0.substring(0, var1);
        } else {
            int var2;
            for(var2 = 0; var2 < var0.length() && !Character.isDigit(var0.charAt(var2)); ++var2) {
            }

            var3 = var0.substring(0, var2);
        }

        System.out.println("getInternalDevName(): " + var3);
        return var3;
    }

    public static String getLifetimeWriteKbytes() {
        String var0 = getInternalDataPartitionDevName();
        String var4;
        if (var0.equals("unknown")) {
            var4 = "-1";
            return var4;
        } else if (!MemoryStatus.getInternalFilesystem().equals("ext4")) {
            return "-1";
        } else {
            String var3;
            try {
                String[] var2 = new String[]{"/system/bin/sh", "-c", "cat /sys/fs/ext4/" + var0 + "/lifetime_write_kbytes"};
                var3 = (new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec(var2).getInputStream()))).readLine();
            } catch (IOException var5) {
                return "-1";
            }

            var4 = var3;
            if (var3 != null) {
                return var4;
            } else {
                return "-1";
            }
        }
    }

    public static long[] getStatfsFromPath(String var0) {
        long[] var1 = new long[7];
        GET_STATFS_FROM_PATH(var0, var1);
        return var1;
    }

    public static ArrayList<NameValuePair> info_to_Arrs(Context var0, int var1) {
        ArrayList var2 = new ArrayList();
        String var3;
        String var4;
        String var5;
        String var6;
        if (var1 == 0) {
            var3 = "/data";
            var4 = MemoryStatus.getInternalFilesystem();
            var5 = MemoryStatus.getInternalScheduler();
            var6 = getLifetimeWriteKbytes();
        } else {
            var3 = MemoryStatus.getSDExternalPath(var0);
            var4 = MemoryStatus.getSDExternalScheduler();
            var5 = MemoryStatus.getSDExternalScheduler();
            var6 = "-1";
        }

        long[] var7 = getStatfsFromPath(var3);
        String var8;
        String var9;
        String var10;
        String var11;
        String var12;
        String var13;
        if (var7[0] != -1L) {
            var8 = Long.toString(var7[0] * var7[5]);
            var9 = Long.toString(var7[1] * var7[5]);
            var10 = Long.toString(var7[2] * var7[5]);
            var11 = Long.toString(var7[3]);
            var12 = Long.toString(var7[4]);
            var13 = Long.toString(var7[5]);
        } else {
            var8 = "-1";
            var9 = "-1";
            var10 = "-1";
            var11 = "-1";
            var12 = "-1";
            var13 = "-1";
        }

        var2.add(new BasicNameValuePair("target", var3));
        var2.add(new BasicNameValuePair("filesystem", var4));
        var2.add(new BasicNameValuePair("io_scheduler", var5));
        var2.add(new BasicNameValuePair("total_space", var8));
        var2.add(new BasicNameValuePair("free_space", var9));
        var2.add(new BasicNameValuePair("available_space", var10));
        var2.add(new BasicNameValuePair("total_filenodes", var11));
        var2.add(new BasicNameValuePair("free_filenodes", var12));
        var2.add(new BasicNameValuePair("block_size", var13));
        var2.add(new BasicNameValuePair("lifetime_write_kbytes", var6));
        var2.add(new BasicNameValuePair("available_processors", Integer.toString(Runtime.getRuntime().availableProcessors())));
        var2.add(new BasicNameValuePair("governor", MemoryStatus.getGovernor()));
        var2.add(new BasicNameValuePair("io_is_busy", MemoryStatus.getGovernor_IO_IS_BUSY()));
        var2.add(new BasicNameValuePair("cpu_hardware", getCpuHardware()));
        var2.add(new BasicNameValuePair("charging_status", ChargingState.getChargingState(var0)));
        var2.add(new BasicNameValuePair("charging_level", Integer.toString(ChargingState.getBatteryLevel(var0))));
        var2.add(new BasicNameValuePair("android_id", Secure.getString(var0.getContentResolver(), "android_id")));

        try {
            var2.add(new BasicNameValuePair("androbench_ver", var0.getPackageManager().getPackageInfo(var0.getPackageName(), 0).versionName));
        } catch (NameNotFoundException var32) {
            var2.add(new BasicNameValuePair("androbench_ver", "unknown"));
        }

        var2.add(new BasicNameValuePair("kernel_ver", VersionCheck.getKernelVersion()));
        var2.add(new BasicNameValuePair("b_version_codename", VERSION.CODENAME));
        var2.add(new BasicNameValuePair("b_version_incremental", VERSION.INCREMENTAL));
        var2.add(new BasicNameValuePair("b_version_release", VERSION.RELEASE));
        var2.add(new BasicNameValuePair("b_version_sdk_int", Integer.toString(VERSION.SDK_INT)));
        var2.add(new BasicNameValuePair("b_brand", Build.BRAND));
        var2.add(new BasicNameValuePair("b_device", Build.DEVICE));
        var2.add(new BasicNameValuePair("b_display", Build.DISPLAY));
        var2.add(new BasicNameValuePair("b_hardware", Build.HARDWARE));
        var2.add(new BasicNameValuePair("b_id", Build.ID));
        var2.add(new BasicNameValuePair("b_manufacturer", Build.MANUFACTURER));
        var2.add(new BasicNameValuePair("b_model", Build.MODEL.toString().replaceAll(" ", "%20")));
        var2.add(new BasicNameValuePair("b_product", Build.PRODUCT));
        return var2;
    }

    public static String info_to_str(Context var0, int var1) {
        ArrayList var2 = new ArrayList();
        String var3;
        String var4;
        String var5;
        String var6;
        if (var1 == 0) {
            var3 = "/data";
            var4 = MemoryStatus.getInternalFilesystem();
            var5 = MemoryStatus.getInternalScheduler();
            var6 = getLifetimeWriteKbytes();
        } else {
            var3 = MemoryStatus.getSDExternalPath(var0);
            var4 = MemoryStatus.getSDExternalScheduler();
            var5 = MemoryStatus.getSDExternalScheduler();
            var6 = "-1";
        }

        long[] var7 = getStatfsFromPath(var3);
        String var8;
        String var9;
        String var10;
        String var11;
        String var12;
        String var13;
        if (var7[0] != -1L) {
            var8 = Long.toString(var7[0] * var7[5]);
            var9 = Long.toString(var7[1] * var7[5]);
            var10 = Long.toString(var7[2] * var7[5]);
            var11 = Long.toString(var7[3]);
            var12 = Long.toString(var7[4]);
            var13 = Long.toString(var7[5]);
        } else {
            var8 = "-1";
            var9 = "-1";
            var10 = "-1";
            var11 = "-1";
            var12 = "-1";
            var13 = "-1";
        }

        Pair var14 = new Pair("target", var3);
        var2.add(var14);
        Pair var16 = new Pair("filesystem", var4);
        var2.add(var16);
        Pair var18 = new Pair("io_scheduler", var5);
        var2.add(var18);
        Pair var20 = new Pair("total_space", var8);
        var2.add(var20);
        Pair var22 = new Pair("free_space", var9);
        var2.add(var22);
        Pair var24 = new Pair("available_space", var10);
        var2.add(var24);
        Pair var26 = new Pair("total_filenodes", var11);
        var2.add(var26);
        Pair var28 = new Pair("free_filenodes", var12);
        var2.add(var28);
        Pair var30 = new Pair("block_size", var13);
        var2.add(var30);
        Pair var32 = new Pair("lifetime_write_kbytes", var6);
        var2.add(var32);
        var2.add(new Pair("available_processors", Integer.toString(Runtime.getRuntime().availableProcessors())));
        var2.add(new Pair("governor", MemoryStatus.getGovernor()));
        var2.add(new Pair("io_is_busy", MemoryStatus.getGovernor_IO_IS_BUSY()));
        var2.add(new Pair("cpu_hardware", getCpuHardware()));
        var2.add(new Pair("charging_status", ChargingState.getChargingState(var0)));
        var2.add(new Pair("charging_level", Integer.toString(ChargingState.getBatteryLevel(var0))));
        var2.add(new Pair("android_id", Secure.getString(var0.getContentResolver(), "android_id")));

        try {
            var2.add(new Pair("androbench_ver", var0.getPackageManager().getPackageInfo(var0.getPackageName(), 0).versionName));
        } catch (NameNotFoundException var58) {
            var2.add(new Pair("androbench_ver", "unknown"));
        }

        var2.add(new Pair("kernel_ver", VersionCheck.getKernelVersion()));
        var2.add(new Pair("b_version_codename", VERSION.CODENAME));
        var2.add(new Pair("b_version_incremental", VERSION.INCREMENTAL));
        var2.add(new Pair("b_version_release", VERSION.RELEASE));
        var2.add(new Pair("b_version_sdk_int", Integer.toString(VERSION.SDK_INT)));
        var2.add(new Pair("b_brand", Build.BRAND));
        var2.add(new Pair("b_device", Build.DEVICE));
        var2.add(new Pair("b_display", Build.DISPLAY));
        var2.add(new Pair("b_hardware", Build.HARDWARE));
        var2.add(new Pair("b_id", Build.ID));
        var2.add(new Pair("b_manufacturer", Build.MANUFACTURER));
        var2.add(new Pair("b_model", Build.MODEL));
        var2.add(new Pair("b_product", Build.PRODUCT));
        String var56 = "";

        for(int var57 = 0; var57 < var2.size(); ++var57) {
            var56 = var56 + "&" + (String)((Pair)var2.get(var57)).first + "=" + (String)((Pair)var2.get(var57)).second;
        }

        return var56;
    }
}
